<template>
  <div class="layout-all">
    <control :config="config" />
    <div class="layout-header" style="float:left">
      <router-link to="./form/">
        <el-button
          type="primary"
          icon="el-icon-plus"
          style="margin-left:0px"
        >添加</el-button>
      </router-link>
    </div>
    <div class="layout-content">
      <el-table
        :data="tableData"
        stripe
        align="center"
        highlight-current-row
        style="width: 100%;margin-top:50px"
      ><el-table-column align="center" prop="id" label="序号" width="70" :fixed="isMobile()?'left':undefined"/>
        <el-table-column align="center" prop="title" label="店铺名" width="150" />
        <el-table-column align="center" prop="nickname" label="店主昵称" width="150">
           <template slot-scope="scope">
             <div v-if="scope.row.user" icon="el-icon-platform-eleme" :style="{color:scope.row.user.sex==1?'#409eff':scope.row.user.sex==0?'#a4959a':'#D650BD'}" >
               {{scope.row.user.nickname}}</div>
            </template>
        </el-table-column>
        <el-table-column align="center" prop="sub_title" label="店铺简称" width="100" />
        <el-table-column align="center" prop="create_time" label="创建日期" width="180" />
        <el-table-column align="center" prop="is_system" label="是否是官方店铺" width="180">
          <template slot-scope="scope">
            <el-button
              :type="scope.row.is_system === 1 ? 'primary' : 'success'"
              size="mini"
              @click="change_status(scope.row.id,'is_system' ,scope.row.is_system)"
            >{{ scope.row.is_system === 1 ? "是" : "否" }}</el-button>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="status" label="是否启用" width="80">
          <template slot-scope="scope">
            <el-button
              :type="scope.row.status === 1 ? 'primary' : 'success'"
              size="mini"
              @click="change_status(scope.row.id,'status' ,scope.row.status)"
            >{{ scope.row.status === 1 ? "是" : "否" }}</el-button>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="auto_check" label="自动审核" width="100">
          <template slot-scope="scope">
            <el-button
              :type="scope.row.auto_check === 1 ? 'primary' : 'success'"
              size="mini"
              @click="change_status(scope.row.id,'auto_check' ,scope.row.auto_check)"
            >{{ scope.row.auto_check === 1 ? "是" : "否" }}</el-button>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="money" label="余额" width="100" />
        <el-table-column align="center" prop="address" label="门店地址" width="100" />
        <el-table-column align="center" prop="account" label="登录账户" width="150" />
        <el-table-column align="center" prop="tel" label="门店电话" width="150" />
        <el-table-column align="center" prop="goods_count" label="上传商品上限" width="150" >
          <template slot-scope="scope">
            {{scope.row.goods_count==0?'不限':scope.row.goods_count}}
          </template>
        </el-table-column>

        <el-table-column align="center" prop="description" label="介绍" />
        <el-table-column
          align="center"
          prop="telephone"
          :fixed="isMobile()?undefined:'right'"
          width="240"
          label="操作"
        >
          <template slot-scope="scope">
            <router-link :to="'./form/' + scope.row.id">
              <el-button size="small" type="primary" icon="el-icon-edit" />
            </router-link>
            <el-button
              size="small"
              type="danger"
              v-if="scope.row.id>1"
              icon="el-icon-delete"
              @click="onDel(scope.row.id)"
            />
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-pagination
      :current-page="current_page"
      :page-size="per_page"
      layout="total, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
import control from '../../components/control/control'
export default {
  name:'shop_index',
  components: { control },
  data() {
    return {
      config: [
        { type: 'text', placeholder: '请输入店铺名', field: 'title', val: '' }
      ],
      dateTime: '',
      value: '',
      searchWhere: {
        title: ''
      },
      tableData: [],
      total: 0,
      current_page: 1,
      per_page: 14
    }
  },
  activated(){
    if(this.$getUpdate()){
      this.onSearch()
    }
  },
  created() {
    this.onSearch()
  },
  methods: {
    // 查询
    handleSizeChange(val) {
      this.onSearch()
    },
    handleCurrentChange(val) {
      this.current_page = val
      this.onSearch()
    },
    onSearch() {
      const form = {}
      form.page = this.current_page
      form.map = this.searchWhere
      this.get('/admin/Shop/index', form, 'POST').then(e => {
        this.tableData = e.list.data
        this.per_page = e.list.per_page
        this.total = e.list.total
        this.current_page = e.list.current_page
      })
    },
    // 添加
    onAdd() {},
    // 编辑
    onEdit(id) {
      console.log(id)
    },
    // 修改状态
    change_status(id, field, val) {
      if(id==1){
        this.$msg_ok('error','此店铺不可修改')
        return
      }
      this.update(id, val, field, 'Shop').then(e => {
        e ? this.onSearch() : ''
      })
    },
    // 删除
    onDel(id) {
      this.$msg_confirm().then(e => {
        if (e) {
          this.get('/admin/Shop/del?id=' + id, this.form, 'POST').then(e => {
            this.onSearch()
          })
        }
      })
    }
  }
}
</script>

<style>
.layout-all {
  margin-top: 20px;
  margin-left: 10px;
}
.layout-content {
  margin-top: 20px;
}
</style>>
